package com.imay.live.adapter;

import android.text.SpannableStringBuilder;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.imay.live.R;
import com.imay.live.helper.GiftHelper;
import com.imay.live.model.GiftModel;
import com.imay.live.model.ProfileRankingSendGiftModel;
import com.imay.live.utils.GlideUtil;
import com.imay.base.util.SpannableStringUtils;
import com.imay.live.utils.TimeUtil;

import java.util.List;

/**
 * Created by  nick on 2017/4/21 0021.
 * 我的->送礼物排行榜
 */

public class ProfileSendGiftRankingAdapter extends BaseQuickAdapter<ProfileRankingSendGiftModel,BaseViewHolder> {


    private GiftHelper giftHelper;
    public ProfileSendGiftRankingAdapter(List<ProfileRankingSendGiftModel> data) {
        super(R.layout.item_profile_send_gift_ranking,data);
        giftHelper = GiftHelper.getInstance();
    }

    @Override
    protected void convert(BaseViewHolder helper, ProfileRankingSendGiftModel item) {
        helper.setText(R.id.tv_time_profile_ranking, TimeUtil.getFriendlyTime(item.getSendTime()));
        ImageView iv_head_img_profile_ranking = helper.getView(R.id.iv_head_img_profile_ranking);
        ImageView iv_gift_profile_ranking = helper.getView(R.id.iv_gift_profile_ranking);
        GlideUtil.loadCircleImage(iv_head_img_profile_ranking, item.getToUser().getImgHead(), R.mipmap.pnl_00_head108);
        GiftModel model = giftHelper.getGift((int) item.getGiftId());
        String giftName = "";
        if (model!=null){
            GlideUtil.loadImage(iv_gift_profile_ranking, model.getGiftPic());
            giftName = model.getGiftName();
        }else{
            giftName = mContext.getString(R.string.gift);
            iv_gift_profile_ranking.setImageDrawable(null);
        }
        helper.setText(R.id.tv_name_profile_ranking,getContent(item.getToUser().getNick(),giftName,item.getCount()));



    }

    private SpannableStringBuilder getContent(String userName,String giftName,int count){
        SpannableStringBuilder builder = SpannableStringUtils.getBuilder(mContext.getString(R.string.profile_gift_send)).setForegroundColor(mContext.getResources().getColor(R.color.text_75))
                .append(userName).setForegroundColor(mContext.getResources().getColor(R.color.text_21))
                .append(count+"").setForegroundColor(mContext.getResources().getColor(R.color.text_75))
                .append(mContext.getString(R.string.profile_gift_a)).setForegroundColor(mContext.getResources().getColor(R.color.text_75))
                .append(giftName).setForegroundColor(mContext.getResources().getColor(R.color.text_75))
                .create();
        return builder;
    }
}
